var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cashPledge: '',
    rent: '',
    cardPrice: '',
    canBack: '',
    phone: '',
    showPage:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      cardNumber: options.card
    })
    that.getInfo()
  },
  callPhone(e){
    console.log(e.currentTarget.dataset.hotline)
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.hotline //仅为示例，并非真实的电话号码
    })
  },
  getInfo(){
    var that = this
    app.executeRequest(function (header) {
      wx.showLoading({
        title: '加载中',
      })
      wx.request({
        url: app.BASE_URL + '/hospitalized/getRefundNeedInfo',
        header: header,
        data: {
          cardNumber: that.data.cardNumber
        },
        success: (res) => {
          getApp().hideLoading()
          console.log(res)
          if (res.data.result == 0) {
          console.log(res,"resAAA")
          that.setData({
              cashPledge: res.data.data.totalPaymentAmount,
              rent: res.data.data.totalConsumeAmount,
              cardPrice: res.data.data.cardFee,
              canBack: res.data.data.totalRefundableBalance,
              phone: res.data.data.nursePhone,
              showPage:true
            })
          } else {
            that.setData({
              showdialog:true,
              title: res.description,
            })
          }

        }
      })
    })
  },
  jumpWIth() {
    var that = this
    // if(that.data.canBack>0){
      wx.showLoading({
        title: '加载中',
      })
      app.executeRequest(function (header) {
        wx.request({
          url: app.BASE_URL + '/hospitalized/refundDeposit',
          header: header,
          data: {
            cardNum: that.data.cardNumber
          },
          success: (res) => {
            getApp().hideLoading()
            console.log(res)
            if(res.data.result == 0){
              wx.navigateTo({
                url: '../Withdraw/Withdraw?card=' + that.data.cardNumber + '&canBack=' + that.data.canBack + '&cardPrice=' + that.data.cardPrice + '&phone=' + that.data.phone + '&time=' + res.data.data.refundTime,
              })
            }else{
              that.setData({
                showdialog:true,
                title: res.data.description,
              })
            }

          },
          fail:(res)=>{
            that.setData({
              showdialog:true,
              title: res.data.description,
            })
          }
        })
      })


  },
  jumpUsage() {
    var that = this
    wx.navigateTo({
      url: '../ICusageRecord/ICusageRecord?card=' + that.data.cardNumber,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})